package post;

import java.io.IOException;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import yxnote.PMF;

public class Create extends HttpServlet{
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String title = req.getParameter("title");
        String category = req.getParameter("category");
        String content = req.getParameter("content");
        
        Post post = new Post(title, category, content);
        
        PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
            pm.makePersistent(post);
        } finally {
            pm.close();
        }
        
        resp.sendRedirect("/post/list.jsp");
    }
}
